﻿using System;
using System.Collections;

using LeanEngine.Entity;
using LeanEngine.Collections;

namespace LeanEngine.Data
{
    /// <summary>
    /// Interface that represents create, read, update and delete sql commands.
    /// </summary>
    public interface ICrudCommand
    {
        /// <summary>
        /// Gets the builder of the sql command texts.
        /// </summary>
        ISqlTextBuilder SqlTextBuilder { get; }

        /// <summary>
        /// Execute an insert sql command against the database.
        /// </summary>
        /// <exception cref="System.Data.DataException"></exception>
        /// <param name="value">The transfer object's to be saved on database</param>
        void ExecuteInsert(PlainEntity value);

        /// <summary>
        /// Execute an insert command for all relation value values into the specified table.
        /// </summary>
        /// <exception cref="ArgumentNullException"></exception>
        /// <param name="table">The relation table name.</param>
        /// <param name="value">The first relation transfer object instance.</param>
        /// <param name="relationList">The list of tranfer object values of the second relation.</param>
        void ExecuteInsertRelation(string table, PlainEntity value, IList relationList);

        /// <summary>
        /// Execute an update sql command against the database.
        /// </summary>
        /// <exception cref="System.Data.DataException"></exception>
        /// <param name="value">The transfer object's to be saved on database</param>
        void ExecuteUpdate(PlainEntity value);

        /// <summary>
        /// Execute a delete sql command against the database.
        /// </summary>
        /// <exception cref="System.Data.DataException"></exception>
        /// <param name="value">The transfer object will be deleted.</param>
        void ExecuteDelete(PlainEntity value);

        /// <summary>
        /// Execute a delete sql command to delete all relation values of the specified table.
        /// </summary>
        /// <exception cref="ArgumentNullException"></exception>
        /// <param name="table">The relation table name.</param>
        /// <param name="value">The first relation transfer object instance.</param>
        /// <param name="relationList">The list of tranfer object values of the second relation.</param>
        void ExecuteDeleteRelation(string table, PlainEntity value, IList relationList);

        /// <summary>
        /// Execute a count sql command against the database.
        /// </summary>
        /// <exception cref="System.Data.DataException"></exception>
        /// <param name="entityType">The type of the transfer object.</param>
        long ExecuteCount(Type entityType);

        /// <summary>
        /// Execute a select command againt the database and returns a paged list of data.
        /// </summary>
        /// <typeparam name="T">Transfer object type</typeparam>
        /// <param name="pageIndex">Page index to be searched for</param>
        /// <param name="pageSize">Page size to be returned</param>
        /// <returns>A page list class with its itens returned by the command</returns>
        PagedList<T> ExecuteReader<T>(int pageIndex, int pageSize)
            where T : PlainEntity, new();

        /// <summary>
        /// Execute a select command to retrieve all values of a transfer object and fill it with.
        /// </summary>
        /// <exception cref="System.Data.DataException"></exception>
        /// <param name="value">The transfer object will be readed.</param>
        PlainEntity ExecuteReader(PlainEntity value);
    }
}
